<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
  <head> 
	<%@ include file="/platform/style.jsp"%>
	<style>
		img.channelimg{height:110px;height:50px}
	</style>
  	<script>
  	
  	function caozFormatter(value,row){
		var h='';
		if(value.split(".").length==1)
			h+='<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addClass(\''+value+'\','+row.id+')" style="width:102px;">添加一级分类</a>';
		else if(value.split(".").length==2)h+='<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addClass(\''+value+'\','+row.id+')" style="width:102px;">添加子分类</a>';
		else h+='<span style="width:128px;display:inline-block"></span>';
		h+='<a href="javascript:void(0);" class="ui_btn marginR8" onclick="edit('+row.id+')">编辑</a>';
		h+='<a href="javascript:void(0);" class="ui_btn_2 marginR8" onclick="openmodel('+row.id+')">商品模型</a>';
		if(value.split(".").length==1)
			h+='<a href="javascript:void(0);" class="ui_btn_disabled">删除</a>';
		else h+='<a href="javascript:void(0);" class="ui_btn" onclick="del('+row.id+')">删除</a>';
		
		return h;
	}
	
	function addRoot(){
		addClass($getByName("rootcode").val());
	}
	function addClass(parcode){
		var str=ctx+"/products/ProductClassPage@addShow.page?bean.parcode="+parcode+"&rootCode="+$getByName("rootcode").val();
		window.parent.$w.openDialog({url:str,title:'添加商品分类',w:600,h:400,afterClose:function(json){
			if(json=='ok')$('#tree').treegrid("reload");//刷新
		}});
	}
	
	function edit(id){
		var str=ctx+"/products/ProductClassPage@addShow.page?bean.id="+id+"&rootCode="+$getByName("rootcode").val();
		window.parent.$w.openDialog({url:str,title:'修改商品分类',w:600,h:400,afterClose:function(json){
			if(json=='ok')$('#tree').treegrid("reload");//刷新
		}});
	}
	function del(id){
		var chs=$('#tree').treegrid("getChildren",id);
		if(chs.length>0){
			window.parent.$w.infoMsg("有子分类不能删除！");
			return false
		}
		window.parent.$w.confirmMsg("确定删除？", function(r){
			if(r){
				$w.doUrl(ctx+"/products/ProductClassPage@del.page?bean.id="+id,{},function(json){
					$('#tree').treegrid("reload");
				})
			}
		})
	}
	
	function openmodel(pid){
		$w.openDialog({url:ctx+'/products/ProductClassPage@showModelAttr.page?bean.classid='+pid,title:"商品模型属性管理",w:700,h:450,maximized:true,afterClose:function(re){
			
		}});
	}
  	</script>
  </head>
  
  <body class="easyui-layout">
	<div data-options="region:'center'" class="bodybg">
		<input name="rootcode" value="<%=request.getParameter("code")==null?"":request.getParameter("code") %>" type="hidden">
		<div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
			<a href="javascript:;" class="easyui-linkbutton" iconCls="icon_add" plain="true" onclick="addRoot()">添加一级分类</a>
		</div>
		<div class="ui_line" style="margin-top:10px"></div>
		
		<table id="tree" class="easyui-treegrid"
			data-options="fit:true,border:false,rownumbers: true,
			url: '<%=path %>/products/ProductClassPage@loadClassList.page?bean.code=<%=request.getParameter("code")==null?"":request.getParameter("code") %>',
			idField: 'id',
			fitColumns:true,
			treeField: 'name'">
			<thead>
				<tr>
					<th data-options="field:'id',width:40" align="center">ID</th>
					<th data-options="field:'name',width:fixWidth(0.4)">名称</th>
					<th data-options="field:'status',width:fixWidth(0.1)"  align="center">状态</th>
					<th data-options="field:'orderno',width:fixWidth(0.1)"  align="center">排序</th>
					<th data-options="field:'code',width:290,formatter:caozFormatter" align="center">操作</th>
				</tr>
			</thead>
		</table>
	</div>
	
  </body>
</html>
